package com.demo.controller;

import com.demo.common.Result;
import com.demo.mapper.ClassroomMapper;
import com.demo.mapper.CourseMapper;
import com.demo.mapper.TimeSlotMapper;
import com.demo.pojo.entity.Classroom;
import com.demo.pojo.entity.Course;
import com.demo.pojo.entity.TimeSlot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 调试控制器
 */
@RestController
@RequestMapping("/debug")
@CrossOrigin
public class DebugController {
    
    @Autowired
    private CourseMapper courseMapper;
    
    @Autowired
    private ClassroomMapper classroomMapper;
    
    @Autowired
    private TimeSlotMapper timeSlotMapper;
    
    /**
     * 检查数据库连接和数据
     */
    @GetMapping("/check-data")
    public Result<Map<String, Object>> checkData() {
        try {
            Map<String, Object> result = new HashMap<>();
            
            // 检查课程数据
            List<Course> courses = courseMapper.selectList(null);
            result.put("courseCount", courses.size());
            result.put("courses", courses);
            
            // 检查教室数据
            List<Classroom> classrooms = classroomMapper.selectList(null);
            result.put("classroomCount", classrooms.size());
            result.put("classrooms", classrooms);
            
            // 检查时间段数据
            List<TimeSlot> timeSlots = timeSlotMapper.selectList(null);
            result.put("timeSlotCount", timeSlots.size());
            result.put("timeSlots", timeSlots);
            
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("检查数据失败：" + e.getMessage());
        }
    }
    
    /**
     * 检查特定学期的数据
     */
    @GetMapping("/check-semester/{semester}")
    public Result<Map<String, Object>> checkSemesterData(@PathVariable String semester) {
        try {
            Map<String, Object> result = new HashMap<>();
            
            // 检查课程数据
            List<Course> courses = courseMapper.selectList(null);
            result.put("courseCount", courses.size());
            
            // 检查教室数据
            List<Classroom> classrooms = classroomMapper.selectList(null);
            result.put("classroomCount", classrooms.size());
            
            // 检查特定学期的时间段数据
            List<TimeSlot> timeSlots = timeSlotMapper.selectList(
                new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<TimeSlot>()
                    .eq("semester", semester)
            );
            result.put("timeSlotCount", timeSlots.size());
            result.put("semester", semester);
            
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("检查学期数据失败：" + e.getMessage());
        }
    }
}
























